#!/usr/bin/python
# Copyright 2012, Kitware, Inc.

"""Exercise 1: Basic Python"""

import sys
import math


def sqrt_dict(n):
    """Compute a dictionary mapping the first n integers to square roots."""
    d = dict()
    for i in range(n):
        d[i] = math.sqrt(i)
    return d


def sqrt_dict_alternate(n):
    """Compute a dictionary mapping the first n integers to square roots."""
    # This alternate one-line solution uses list comprehensions
    # http://docs.python.org/tutorial/datastructures.html#list-comprehensions
    return dict([(i, math.sqrt(i)) for i in range(n)])


def main():
    """The main function."""
    # parse the command line argument
    # require exactly 1 argument (argv[0] is the script name)
    if len(sys.argv) != 2:
        print "usage: %s number" % sys.argv[0]
        return

    # convert the command line argument to an interger
    num = int(sys.argv[1])
    # call the function
    values = sqrt_dict(num)
    # print the result
    print values


if __name__ == "__main__":
    main()
